#include <stdio.h>
#include <stdlib.h>

#include "link.h"

/* Creation */
link* l_new()
{
	link *This = malloc(sizeof(link));
	if (!This) return 0;
	l_init(This);
	This->destroy = n_destroy;
	return This;
}

/* Name handling */
/* set line nb */
void l_lset(link *This, char* newl)
{
	This->line = newl;
}
/* get line nb */
char* l_lget(link *This)
{
	return ((This->line));
}

/* Extremities */
	/* Set ext1 */
void l_setext1 (link *This, node *ext)
{
	This->ext1 = *ext;
}
	/* Set ext2 */
void l_setext2 (link *This, node *ext)
{
	This->ext2 = *ext;
}
	/* Get ext1 */
node* l_getext1(link *This)
{
	node *res = NULL;
	res = &(This->ext1);
	return (res);
}
	/* Get ext2 */
node* l_getext2(link *This)
{
	node *res = NULL;
	res = &(This->ext2);
	return (res);
}

/* Display */
void l_print (link *This)
{
	node *e1,*e2;
	
	e1 = (This->getext1(This));
	e2 = (This->getext2(This));
	
	printf("line: %s\n", This->get_line(This));
	printf("ext1: %s, ext2: %s\n", e1->name, e2->name);
	printf("\n");
}

/* Init */
static void l_init(link *This)
{
	This->set_line = l_lset;
	This->get_line = l_lget;
	This->setext1  = l_setext1;
	This->setext2  = l_setext2;
	This->getext1  = l_getext1;
	This->getext2  = l_getext2;
	This->print    = l_print;
	This->destroy  = l_destroy;
	This->line     = "Untitled";
}

/* Destroy */
void l_destroy(link *This)
{
	free(This);
}